package org.yx.service.sbas.update_product_status;

import org.yx.exception.BizException;
import org.yx.models.SbasProdMat;
import org.yx.utils.BaseService;
import org.yx.utils.FieldMap;

/**
 * 更新产品状态，如删除
 * @author zxw
 * @since 2018/03/25
**/
public class SbasUpdateProductStatusService extends BaseService {
	public SbasUpdateProductStatusOut updateProductStatus(SbasUpdateProductStatusIn in) throws Exception {
		checkStringNotBlank(in, "matCode,matVer");

		SbasProdMat oldMat = selectOne(SbasProdMat.class, in.getUserToken().getOrgCode(), in.getMatCode(), in.getMatVer());
		if (oldMat == null || new Character('D').equals(oldMat.getMatStatus())) {
			throw new BizException("SBAS-0001", new FieldMap("matCode", in.getMatCode()));
		}
		if (!new Character('D').equals(in.getStatus())) {
			throw new BizException("SYS-0005", new FieldMap("parameter", "status"), new FieldMap("value", in.getStatus()));
		}

		oldMat.setMatStatus(in.getStatus());

		update(oldMat, "matStatus");

		SbasUpdateProductStatusOut out = new SbasUpdateProductStatusOut();

		return out;
	}
}